# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: Jeff Stewart

TEMPLATE=app

google {
  PROVIDER = util/provider_google.cc
  RESOURCES += resources_google.qrc
  DEFINES += INIT_BRANDING_RESOURCE='"Q_INIT_RESOURCE(resources_google)"' \
             COMPANY_NAME='\\"Google\\"' \
             COMPANY_DOMAIN='\\"google.com\\"' \
             STANDARD_LOGO='\\":/graphics/resources/gmail.png\\"' \
             ALTERNATE_LOGO='\\":/graphics/resources/googlemail.png\\"'
  mac_icon {
    ICON = resources/GmailIcon.icns
  } else {
    DEFINES += WINDOW_ICON='\\":/graphics/resources/gmail_favicon.PNG\\"'
  }
} else {
  PROVIDER = util/provider.cc
}

CONFIG += qt
CONFIG += debug_and_release
CONFIG += build_all

CONFIG(debug, debug|release) {
  TARGET = debug_PopImapTroubleshooter
  DESTDIR = build/dbg
  MOC_DIR = build/dbg/obj
  RCC_DIR = build/dbg/obj
  OBJECTS_DIR = build/dbg/obj
} else {
  TARGET = PopImapTroubleshooter
  DESTDIR = build/opt
  MOC_DIR = build/opt/obj
  RCC_DIR = built/opt/obj
  OBJECTS_DIR = build/opt/obj
}

GENFILE_DIR=$${MOC_DIR}
TRANS_SRCDIR = translations
RESOURCES += resources.qrc

# The set of languages we have translations ready for that we want to include
# in the build.  When you update this list, also update ./translations.qrc and
# ./mk_file.
TRANS_LANGS = de de_CH en en_GB en_IE en_IN en_SG en_ZA es es_419 \
              es_AR es_BO es_CL es_CO es_CR es_DO es_EC es_GT es_HN \
              es_MX es_NI es_PA es_PE es_PR es_PY es_SV es_US es_UY es_VE \
              fr gsw he it ja ln nl pt pt_BR tr zh zh_CN zh_HK zh_TW

# Add the pseudo translations.
TRANS_LANGS += en_US_accented en_US_doublevowels

# The default value for LANG is for the lupdate tool, which apparently
# does not evaluate the for() construct.
LANG = en
for(LANG, TRANS_LANGS): TRANSLATIONS += $${TRANS_SRCDIR}/popdiag_$${LANG}.ts

QT += core gui network xml
INCLUDEPATH += .
mac:LIBS += -lcrypto -lssl

win32 {
  HEADERS += config/binversion.h \
             config/outlook.h \
             config/registrykey.h
  SOURCES += config/binversion.cc \
             config/outlook.cc \
             config/registrykey.cc \
             probes/localhost_win.cc
}

unix:!mac {
  SOURCES += probes/localhost_unix.cc
}

mac {
  SOURCES += probes/localhost_mac.cc \
             config/applemail.cc
  HEADERS += config/applemail.h \
             config/applemail_plist.h
  OBJECTIVE_SOURCES += config/applemail_plist.mm

  # TODO: Not the best way to include this.  Find the right way:
  FRAMEWORKS_ROOT = /System/Library/Frameworks
  CURRENT = Versions/Current
  CS_ROOT = $$FRAMEWORKS_ROOT/CoreServices.framework/$$CURRENT/Frameworks
  INCLUDEPATH += $$CS_ROOT/CarbonCore.framework/$$CURRENT/Headers
  INCLUDEPATH += $$FRAMEWORKS_ROOT/CoreFoundation.framework/$$CURRENT/Headers
  LIBS += -framework Foundation
  LIBS += -framework CoreServices
  LIBS += -framework CoreFoundation
}

# Translation Message Bundle
# Since we store our message catalogs in a separate directory and we
# don't want the compiled output placed there, we need custom rules
# to compile it.
# This set of rules needs to compile the .ts files to .qm files, then
# bundle those up in a Qt Resource pack defined by a .qrc file.
# The .qrc file gets compiled using Qt's resource compiler (RCC) into
# .cc source code, which then will be compiled and linked into the
# application.

# Qt's lrelease tool compiles .ts files to .qm files.
lrelease_qm.input = $${TRANSLATIONS}
for(LANG, TRANS_LANGS): lrelease_qm.output += \
                        $${GENFILE_DIR}/popdiag_$${LANG}.qm
for(LANG, TRANS_LANGS): lrelease_qm.commands += \
                        lrelease $${TRANS_SRCDIR}/popdiag_$${LANG}.ts \
                                 -qm $${GENFILE_DIR}/popdiag_$${LANG}.qm;

# Building an XML file using echo is just too painful.  So we keep a staticly
# built copy laying around to use for this purpose.  Copy it to the right
# place and run it through Qt's resource compiler (RCC)
OBJDIR_RCC_SRCS = translations.qrc

# This is like a "genrule" in a makefile.  It's a template.  Variables
# prefixed with a single $ come from the template.  Variables prefixed
# with a double $ ($$) come from the global scope of this file.
# We don't really use it as a template, but we have to declare it that way.
objdir_rcc.input  = OBJDIR_RCC_SRCS
objdir_rcc.output = $${GENFILE_DIR}/translations_qrc.cc
win32 {
  objdir_rcc.commands = copy ${QMAKE_FILE_NAME} $${GENFILE_DIR}/ &&
} else {
  objdir_rcc.commands = cp -f ${QMAKE_FILE_NAME} $${GENFILE_DIR}/ &&
}
objdir_rcc.commands += rcc -name ${QMAKE_FILE_BASE} \
                       -o ${QMAKE_FILE_OUT} \
                       $${GENFILE_DIR}/${QMAKE_FILE_NAME}
objdir_rcc.depends = lrelease_qm
objdir_rcc.variable_out = SOURCES

QMAKE_EXTRA_UNIX_COMPILERS += lrelease_qm objdir_rcc
QMAKE_EXTRA_TARGETS += lrelease_qm objdir_rcc

HEADERS += config/configverifier.h \
           config/thunderbird.h \
           probes/executive.h \
           probes/imapprobe.h \
           probes/linereader.h \
           probes/localhost.h \
           probes/multiprobe.h \
           probes/popprobe.h \
           probes/probe.h \
           probes/smtpprobe.h \
           probes/ssl.h \
           ui/browser.h \
           ui/clientconfigscreen.h \
           ui/configfixscreen.h \
           ui/introscreen.h \
           ui/progressscreen.h \
           ui/reportgen.h \
           ui/thanksscreen.h \
           ui/wizard.h \
           util/common.h \
           util/protocol.h \
           util/provider.h

SOURCES += main.cc \
           config/configverifier.cc \
           config/thunderbird.cc \
           probes/executive.cc \
           probes/imapprobe.cc \
           probes/linereader.cc \
           probes/localhost.cc \
           probes/multiprobe.cc \
           probes/popprobe.cc \
           probes/probe.cc \
           probes/smtpprobe.cc \
           probes/ssl.cc \
           ui/browser.cc \
           ui/clientconfigscreen.cc \
           ui/configfixscreen.cc \
           ui/introscreen.cc \
           ui/progressscreen.cc \
           ui/reportgen.cc \
           ui/thanksscreen.cc \
           ui/wizard.cc \
           util/common.cc \
           util/protocol.cc \
           $${PROVIDER}
